#!/usr/bin/env python
# coding=utf-8
"""
@Author  : youjia - 卞志伟
@file    : 测试pvuv2.py
@contact : bianzhiwei@iyoujia.com
@time    : 2019-09-09 15:12 
@Desc    : 
@Software: PyCharm
"""
import os
import sys

# 当前文件的路径
pwd, filename = os.path.split(os.path.abspath(__file__))
# 当前文件的父路径
father_path = os.path.abspath(os.path.dirname(pwd) + os.path.sep + ".")
# 当前文件的前两级目录
grader_father = os.path.abspath(os.path.dirname(pwd) + os.path.sep + "..")
sys.path.append(pwd)
sys.path.append(father_path)
sys.path.append(grader_father)

# !/usr/bin/python
# ! -*- coding: utf-8 -*-

__auther__ = 'liuansheng'

import MySQLdb


def db_local(func):
    def conn(*args, **kwargs):
        conn = MySQLdb.connect(host='192.168.50.3', port=3306, user='root', passwd='root', db='mayi.com',
                               charset='utf8')
        db = conn.cursor()
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


def ana_r(func):
    def conn(*args, **kwargs):
        conn = MySQLdb.connect(host='172.16.17.10', port=3841, user='ana_r', passwd='select@2015', db='analytics',
                               charset='utf8')
        db = conn.cursor()
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


def ana_admin(func):
    def conn(*args, **kwargs):
        conn = MySQLdb.connect(host='172.16.17.10', port=3841, user='ana_admin', passwd='BFCMt6qKCXO1', db='analytics',
                               charset='utf8')
        db = conn.cursor()
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


def ana_admin_dzreport(func):
    def conn(*args, **kwargs):
        conn = MySQLdb.connect(host='172.16.17.10', port=3840, user='ana_admin', passwd='BFCMt6qKCXO1', db='dz_report',
                               charset='utf8')
        db = conn.cursor()
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


# 本地10 report链接库，可以测试用
def ana_dzreport(func):
    def conn(*args, **kwargs):
        conn = MySQLdb.connect(host='172.16.17.10', port=3840, user='ana_r', passwd='select@2015', db='dz_report',
                               charset='utf8')
        db = conn.cursor()
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


def online_slave(func):
    def conn(*args, **kwargs):
        # #select@2014
        conn = MySQLdb.connect(host='172.16.17.23', port=3306, user='xueqiuyan', passwd='PpEBk76UrWld', db='new_mayi',
                               charset='utf8')
        db = conn.cursor()
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


def online_slave_ana_sel(func):
    def conn(*args, **kwargs):
        # #select@2014
        conn = MySQLdb.connect(host='172.16.17.23', port=3306, user='mayi_yy_r', passwd='pwd4select#', db='ana',
                               charset='utf8')
        db = conn.cursor()
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


def online_slave_vpn(func):
    def conn(*args, **kwargs):
        # #select@2014
        conn = MySQLdb.connect(host='172.16.17.23', port=3306, user='mayi_yy_r', passwd='select@2014', db='new_mayi',
                               charset='utf8')
        db = conn.cursor()
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


def online_weihu(func):
    def conn(*args, **kwargs):
        conn = MySQLdb.connect(host='ku_master', port=3306, user='new_mayi_weihu', passwd='pwd4onlinedb#',
                               db='new_mayi', charset='utf8')
        db = conn.cursor()
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


def online_slave_ana(func):
    def conn(*args, **kwargs):
        conn = MySQLdb.connect(host='172.16.17.23', port=3306, user='ana_admin', passwd='pwd4ana_2016', db='ana',
                               charset='utf8')
        db = conn.cursor()
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


def online_datatmp(func):
    def conn(*args, **kwargs):
        conn = MySQLdb.connect(host='172.16.17.23', port=3306, user='datatmp', passwd='pwd4datatmp#!', db='datatmp',
                               charset='utf8')
        db = conn.cursor()
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


# 添加转换率 数据库链接
def ana_admin_conversion(func):
    def conn(*args, **kwargs):
        conn = MySQLdb.connect(host='172.16.17.10', port=3840, user='ana_admin', passwd='BFCMt6qKCXO1', db='conversion',
                               charset='utf8')
        db = conn.cursor()
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


# 添加日志监控表所在库 数据库链接
# 写库账号，只有 select insert update权限
def ana_admin_monitor_write(func):
    def conn(*args, **kwargs):
        conn = MySQLdb.connect(host='172.16.17.10', port=3840, user='mon_data_w', passwd='p4mon_2a17#', db='mon_data',
                               charset='utf8')
        db = conn.cursor()
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn

    # 读库账号，只有 select权限


def ana_admin_monitor_sel(func):
    def conn(*args, **kwargs):
        conn = MySQLdb.connect(host='172.16.17.10', port=3840, user='mon_data_r', passwd='sle4mon#209!', db='mon_data',
                               charset='utf8')
        db = conn.cursor()
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


def online_slave_vpn_dict(func):
    def conn(*args, **kwargs):
        # #select@2014
        conn = MySQLdb.connect(host='172.16.17.23', port=3306, user='mayi_yy_r', passwd='select@2014', db='new_mayi',
                               charset='utf8')
        db = conn.cursor(MySQLdb.cursors.DictCursor)
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


# im 库
def online_slave_im(func):
    def conn(*args, **kwargs):
        # #select@2014
        conn = MySQLdb.connect(host='172.16.17.23', port=3306, user='mayi_yy_r', passwd='select@2014', db='new_mayi',
                               charset='utf8')
        db = conn.cursor()
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


# 写入埋点数据
def maidian_data_insert(func):
    def conn(*args, **kwargs):
        conn = MySQLdb.connect(host='172.16.17.10', port=3840, user='data_report_w', passwd='pwd4dr#17',
                               db='data_report', charset='utf8')
        db = conn.cursor()
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


# 竞对数据源
def ana_jingdui(func):
    def conn(*args, **kwargs):
        conn = MySQLdb.connect(host='172.16.17.10', port=3840, user='jingdui_w', passwd='pwd4jd#ab!', db='jingdui',
                               charset='utf8')
        db = conn.cursor()
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


# 下面的几个数据元返回值是字典类型
def ana_r_analytics_j(func):
    def conn(*args, **kwargs):
        conn = MySQLdb.connect(host='172.16.17.10', port=3841, user='ana_r', passwd='select@2015', db='analytics',
                               charset='utf8')
        db = conn.cursor(MySQLdb.cursors.DictCursor)
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


def ana_r_dz_report_j(func):
    def conn(*args, **kwargs):
        conn = MySQLdb.connect(host='172.16.17.10', port=3840, user='ana_r', passwd='select@2015', db='dz_report',
                               charset='utf8')
        db = conn.cursor(MySQLdb.cursors.DictCursor)
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


def mayi_yy_r_new_mayi_j(func):
    def conn(*args, **kwargs):
        conn = MySQLdb.connect(host='172.16.17.23', port=3306, user='mayi_yy_r', passwd='pwd4select#', db='new_mayi',
                               charset='utf8')
        db = conn.cursor(MySQLdb.cursors.DictCursor)
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


# 推送统计
def push_r_mayi_push(func):
    def conn(*args, **kwargs):
        conn = MySQLdb.connect(host='172.16.17.16', port=3306, user='push_r', passwd='phr_!a3#', db='mayi_push',
                               charset='utf8')
        db = conn.cursor()
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn


def youjia_tongji(func):
    def conn(*args, **kwargs):
        conn = MySQLdb.connect(host='172.16.10.13', port=3306, user='data_sjz', passwd='W0rVo6Kg87JOnRAr',
                               db='youjia_report', charset='utf8')
        db = conn.cursor()
        result = func(db, *args, **kwargs)
        conn.commit()
        conn.close()
        return result

    return conn
